package com.neusoft.a312cxy.android18cxy.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.neusoft.a312cxy.android18cxy.R;
import com.neusoft.a312cxy.android18cxy.activity.ClubInfoActivity;
import com.neusoft.a312cxy.android18cxy.bean.ClubListBean;

import java.util.List;

/**
 * Created by Young on 2017/9/30.
 */

public class clubAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private Context mContext;//承载上下文
    private List<ClubListBean> mDataList;//动态数组承载数据使用
    private LayoutInflater mLayoutInflater;

    public clubAdapter(Context mContext,List<ClubListBean> mDataList){
        this.mContext=mContext;
        this.mDataList=mDataList;
        mLayoutInflater=LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v=mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_club,parent,false);
        return new ViewHolder(v);
    }
    public void setList(List<ClubListBean> mDataList){
        this.mDataList=mDataList;
        notifyDataSetChanged();
    }
    //将数据绑定到控件
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final  ClubListBean entity=mDataList.get(position);
        if (null==entity)
            return;
        ViewHolder viewHolder= (ViewHolder) holder;
        viewHolder.club_name.setText(entity.getClub_name());
        viewHolder.city_name.setText(entity.getCity_name());
        viewHolder.district_name.setText(entity.getDistrict_name());
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(mContext, ClubInfoActivity.class);
                Bundle bundle = new Bundle();
                bundle.putInt("club_id",entity.getId());
                bundle.putString("userid",entity.getUserid());
                intent.putExtras(bundle);

                //    intent.putExtra("club_name",entity.district_name());
                //     intent.putExtra("club_tel",entity.get);
                //     intent.putExtra("clubthumb",entity.getThumb());
                //          intent.putExtra("food_price",entity.getPrice());
                mContext.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    //找到控件，将其初始化
    public class ViewHolder extends RecyclerView.ViewHolder{
        //ImageView img;
        TextView club_name;
        TextView city_name;
        TextView district_name;
      //  CardView cardview_club;
        public ViewHolder(View itemView) {
            super(itemView);
         //   img= (ImageView) itemView.findViewById(R.id.tra_img);
            club_name= (TextView) itemView.findViewById(R.id.club_name);
            city_name= (TextView) itemView.findViewById(R.id.city_name);
            district_name= (TextView) itemView.findViewById(R.id.district_name);
           /* ac=(RecyclerView)itemView.findViewById(R.id.ac);*/
        }
    }
}
